﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>订单支付</title>
    <script src="~/Scripts/jquery-1.10.2.js"></script>
    <script language="javascript" type="text/javascript">
        $(function () {
            var orderId = '@ViewBag.orderId';
            //是否是微信浏览器打开
            function onBridgeReady() {
                WeixinJSBridge.invoke(
                    'getBrandWCPayRequest', {
                        "appId": "@ViewBag.model.AppID",     //公众号名称，由商户传入
                        "timeStamp": "@ViewBag.model.TimeStamp",         //时间戳，自1970年以来的秒数
                        "nonceStr": "@ViewBag.model.NonceStr", //随机串
                        "package": "@ViewBag.model.Package",
                        "signType": "@ViewBag.model.SignType",         //微信签名方式：
                        "paySign": "@ViewBag.model.PaySign" //微信签名
                    },
                    function (res) {
                        if (res.err_msg == "get_brand_wcpay_request:ok") {
                            window.location.href = "@ViewBag.successUrl";
                        }     // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。
                        else if (res.err_msg == "get_brand_wcpay_request:cancel") {
                            //用户取消支付，
                            window.location.href = "@ViewBag.cancelUrl";
                        }
                        else {
                            //支付异常
                            window.location.href = "@ViewBag.errorUrl";
                        }

                    }
                );
            }
            if (typeof WeixinJSBridge == "undefined") {
                if (document.addEventListener) {
                    document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
                } else if (document.attachEvent) {
                    document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                    document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
                }
            } else {
                onBridgeReady();
            }


            @*if ( orderId) {
                alert("开始支付" + orderId)
                // 当微信内置浏览器完成内部初始化后会触发WeixinJSBridgeReady事件。
                document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
                    //公众号支付
                    $.ajax({
                        type: "GET",
                        url: "@Url.Action("GetPrePayParams")?orderId=" + orderId,
                        dataType: "json",
                        success: function (data) {
                            if (data.Result) {
                                var _data = data.Data;
                                WeixinJSBridge.invoke('getBrandWCPayRequest', {
                                    "appId": _data.AppID,
                                    "timeStamp": _data.TimeStamp,
                                    "nonceStr": _data.NonceStr,
                                    "package": _data.Package,  //预支付ID
                                    "signType": _data.SignType,
                                    "paySign": _data.PaySign
                                }, function (res) {
                                    if (res.err_msg == "get_brand_wcpay_request:ok") {
                                        //--------------------------------------------------支付成功
                                        alert("支付成功")
                                    }
                                    else if (res.err_msg == "get_brand_wcpay_request:cancel") {
                                        //--------------------------------------------------用户取消支付
                                        alert("支付取消")
                                    }
                                    else {
                                        //--------------------------------------------------支付异常
                                        alert("支付失败")
                                    }
                                });
                            } else {
                                //-------------------------预支付失败
                            }
                        }
                    });

                }, false);
            } else {
                //--------------------------------------------------跳转错误页面

                alert("不是微信浏览器" + orderId)
            }
            onBridgeReady();*@
        });
    </script>

</head>
<body>
        @*<form runat="server">
            <br />
            <div align="center">
                <br /><br /><br />
                <asp:Button ID="submit" runat="server" Text="立即支付" OnClientClick="callpay()" style="width:210px; height:50px; border-radius: 15px;background-color:#00CD00; border:0px #FE6714 solid; cursor: pointer;  color:white;  font-size:16px;" />
            </div>
        </form>*@
</body>
</html>
